using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

using System.Runtime.InteropServices;
using Microsoft.CommerceServer.Runtime;
using Microsoft.CommerceServer.Interop;
using Microsoft.CommerceServer.Interop.Orders;

namespace PipelineUI
{
	/// <summary>
	/// Summary description for frmPipeCompUI.
	/// </summary>
	[GuidAttribute("B70632FF-2C52-430c-800C-99944EB59B6C")]
	public class frmPipeCompUI : System.Windows.Forms.Form, IPipelineComponentUI
	{
		private System.Windows.Forms.Button btnOk;
		private System.Windows.Forms.Button btnCancel;

		public bool fOk;

		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmPipeCompUI()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.btnOk = new System.Windows.Forms.Button();
			this.btnCancel = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// btnOk
			// 
			this.btnOk.Location = new System.Drawing.Point(224, 8);
			this.btnOk.Name = "btnOk";
			this.btnOk.TabIndex = 0;
			this.btnOk.Text = "OK";
			this.btnOk.Click += new System.EventHandler(this.btnOk_Click);
			// 
			// btnCancel
			// 
			this.btnCancel.Location = new System.Drawing.Point(224, 40);
			this.btnCancel.Name = "btnCancel";
			this.btnCancel.TabIndex = 1;
			this.btnCancel.Text = "Cancel";
			this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
			// 
			// frmPipeCompUI
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(312, 77);
			this.Controls.Add(this.btnCancel);
			this.Controls.Add(this.btnOk);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "frmPipeCompUI";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Pipeline Component UI";
			this.Load += new System.EventHandler(this.frmPipeCompUI_Load);
			this.ResumeLayout(false);

		}
		#endregion

		private void btnOk_Click(object sender, System.EventArgs e)
		{
			fOk = true;
			this.Hide();
		}

		private void btnCancel_Click(object sender, System.EventArgs e)
		{
			this.Hide();
		}

		private void frmPipeCompUI_Load(object sender, System.EventArgs e)
		{
			fOk = false;
		}

		public void ShowProperties(System.Object pdispComponent)
		{
			try
			{
				// Use IPipelineComponentAdmin Interface to get configuration information
				IPipelineComponentAdmin pdispPCA = (IPipelineComponentAdmin)pdispComponent;

				// Populate a dictionary with component configuration
				Microsoft.CommerceServer.Runtime.IDictionary dictConfig = (Microsoft.CommerceServer.Runtime.IDictionary)pdispPCA.GetConfigData();

				frmPipeCompUI frmPipeCompUIObj = new frmPipeCompUI();
				// Display the properties for the user to edit
				frmPipeCompUIObj.ShowDialog();

				if(frmPipeCompUIObj.fOk)
				{
					// Save entered values into the dictionary


					// Update the component with new configuration information
					pdispPCA.SetConfigData(dictConfig);
				}
			}
			catch(Exception e)
			{
				throw(new Exception(e.Message));
			}
		}
	}
}
